//
//  TPServersTableViewCell.m
//  CloudAtCostPanel
//
//  Created by leonardo on 2017/2/15.
//  Copyright © 2017年 tanpengsccd. All rights reserved.
//

#import "TPServersTableViewCell.h"

#import "TPUIKit.h"

typedef NS_ENUM(NSUInteger ,VpsStatus) {
    VpsStatus_Pending,
    VpsStatus_Installing,
    VpsStatus_PoweredOn,
    VpsStatus_PoweredOff,
};
@interface TPServersTableViewCell()
PRO_S UIImageView * osImgView;
    PRO_S NSArray * osImgs;
PRO_S TPLabel * label_labelWithIp;
//PRO_S TPLabel * label_date;
PRO_S TPLabel * label_configuration;
@end


@implementation TPServersTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier rightBtns:(TPCellUtilityBtns *)rBtns leftBtns:(TPCellUtilityBtns *)lBtns{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier rightBtns:rBtns leftBtns:lBtns];
    if (self) {
        //        8种图标
        UIImage * centos = [UIImage imageNamed:@"centos"];//0
        UIImage * debian = [UIImage imageNamed:@"debian"];//1
        UIImage * win7_2008 = [UIImage imageNamed:@"windows-7"];//2
        UIImage * win2012 = [UIImage imageNamed:@"windows-server-2012"];//3
        UIImage * ubuntu = [UIImage imageNamed:@"ubuntu"];//4
        UIImage * freeBSD = [UIImage imageNamed:@"freebsd"];//5
        _osImgs = @[centos,debian,win7_2008,win2012,ubuntu,freeBSD];
        _osImgView = [UIImageView new];
        
        _label_labelWithIp = [TPLabel labelWithText:@"" Font:FONTSIZE_CONTENT];
        //        _label_date = [TPLabel labelWithText:@"" Font:FONTSIZE_CONTENT];
        _label_configuration = [TPLabel labelWithText:@"" Font:FONTSIZE_CONTENT];
        _label_configuration.textColor  = COLOUR_SUGGEST;
//        _label_configuration.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_osImgView];
        [self.contentView addSubview:_label_labelWithIp];
        //        [self.centerView addSubview:_label_date];
        [self.contentView addSubview:_label_configuration];
        
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setConstraints];
    }
    return  self;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    @throw [NSException exceptionWithName:@"USE initWithStyle reuseIdentifier rightBtns " reason:nil userInfo:nil];

}

-(void)configWithModel:(Data_listservers *)model{
    if ([model.template0 containsString:@"CentOS"]) {
        [_osImgView setImage:_osImgs[0]];
    }else if([model.template0 containsString:@"Debian"]){
        [_osImgView setImage:_osImgs[1]];
    }else if([model.template0 containsString:@"Windows 7"]||[model.template0 containsString:@"Windows 2008"]){
        [_osImgView setImage:_osImgs[2]];
    }else if([model.template0 containsString:@"2012"]){
        [_osImgView setImage:_osImgs[3]];
    }else if([model.template0 containsString:@"Ubuntu"]){
        [_osImgView setImage:_osImgs[4]];
    }else if([model.template0 containsString:@"FreeBSD"]){
        [_osImgView setImage:_osImgs[5]];
    }
    
    [_label_configuration setText:[NSString stringWithFormat:@"%@ CPU| %@MB RAM| %@GB SSD",model.cpu,model.ram,model.storage]];

    
    [_label_labelWithIp setText:[NSString stringWithFormat:@"%@(%@)",model.label?model.label:@"",model.ip]];
    
    if ([model.status containsString:@"On"]) {
        self.contentView.backgroundColor = COLOUR_GREEN;
    }else if ([model.status containsString:@"Off"]) {
        self.contentView.backgroundColor = COLOUR_GRAY;
    }else if ([model.status containsString:@"ail"]) { //fail
        self.contentView.backgroundColor = COLOUR_RED;
    }else if ([model.status containsString:@"ending"]) { //Pending
        self.contentView.backgroundColor = COLOUR_PINK;
    }
    
}

- (void)setConstraints{
    [_osImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.left.mas_equalTo(self.contentView).offset(MARGIN_WINDOW);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    [_label_labelWithIp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_osImgView.mas_right).offset(MARGIN_CELL);
        make.top.mas_equalTo(self.contentView).offset(MARGIN_WINDOW);
        make.right.mas_equalTo(self.contentView).offset(-MARGIN_WINDOW);
    }];
    [_label_configuration mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_osImgView.mas_right).offset(MARGIN_CELL);
        make.right.mas_equalTo(self.contentView).offset(-MARGIN_WINDOW);
        make.top.mas_equalTo(_label_labelWithIp.mas_bottom).offset(MARGIN_CELL);
        make.bottom.mas_equalTo(self.contentView).offset(-MARGIN_WINDOW);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
